$(function(){
    getinfouser()

        // 点击按钮，实现退出功能
        $('#btn_log_out').on('click',function(){
            // console.log(11);
            layer.confirm('确定退出登录？',{icon:3,title : '提示'},
            function(e){
                // 清除本地存储
                localStorage.removeItem('token')
                // 跳转登录页面
                location.href ='/login.html'
            })
        })
})
function getinfouser(){
    $.ajax({
        method : 'GET',
        url:'/my/userinfo',
        // headers:{Authorization = localStorage.getItem('token')||''},
        success(res){
            // console.log(res);
            if(res.status !== 0){
                return layui.layer.msg('获取失败')
            }
            renderavatar(res.data)
        }
        
    })
}
function renderavatar(data){
    let name = data.nickname || data.username
    $('#welcome').html('欢迎&nbsp&nbsp'+name)
    if(data.user_pic === null){
        $('.layui-nav-img').hide()
        let first = name[0].toUpperCase()
        $('.text-avatar').html(first).show()
    }else{
        $('.layui-nav-img').attr('src',data.user_pic).show()
        $('.text-avatar').hide()
    }
}